﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Shopping.Common;
using Shopping.Model;
using Shopping.BLL;
public partial class AS_RegisterCommon : System.Web.UI.Page
{
    private readonly UsersManage bllUser = new UsersManage();
    private ReturnValue ret = new ReturnValue();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string action = Request.QueryString["Action"] as string;
            switch (action)
            {
                case "Register":   //
                    Register();
                    break;
                case "CheckUserRegister":
                    CheckUserRegister();
                    break;
            }
            Response.End();
        }
    }
    private void CheckUserRegister()
    {
        string userName = Utility.G<string>("UserName");
        Users user = bllUser.GetUserInfoByName(userName);
        if (user != null)
        {
            Response.Write(JSONHelper.ObjectToJson(new ReturnValue(ResultType.Success, "存在该用户信息")));
        }
        else
        {
            Response.Write(JSONHelper.ObjectToJson(new ReturnValue(ResultType.Fail, "不存在该用户信息")));
        }
    }

    private void Register()
    {
        string userName = Utility.P<string>("UserName");
        string pwd = Utility.P<string>("PassWord");
        string email = Utility.P<string>("Email");
        string mobile = Utility.P<string>("Mobile");

        Users user = new Users { UserName = userName, PassWord = Utility.MD5(pwd), Email = email, Mobile = mobile, RegisterDate = DateTime.Now, Logins = 1, Moneys = 0.0m, Scores = 0,LastLoginDate=DateTime.Now,LastLoginIP=Request.UserHostAddress,Status="正用" };
        Response.Write(JSONHelper.ObjectToJson(bllUser.Register(user)));
    }
}
